SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		lLara
-- Create date: 21/3/2014
-- Description:	?Descripcion
-- =============================================
CREATE TRIGGER [obd.].[InsertarFlotte]
ON [obd.].[Flotte]
AFTER INSERT
AS 
BEGIN
	SET NOCOUNT ON;

	DECLARE curIns CURSOR LOCAL FOR 
					SELECT idFlotte, ISNULL(protocol,'n/a'), idSystem, 
						ISNULL(ecuHardware,'n/a'), ISNULL(ecuType,'n/a'), ISNULL(engineProject,'n/a'), 
						displacement, ISNULL(emissionConcept,'n/a'), ISNULL(platform,'n/a'), 
						ISNULL(power,'n/a'), ISNULL(gearbox,'n/a'), ISNULL(vehicle,'n/a'), 
						ISNULL(manufacturer,'n/a')
					FROM   inserted;
										
	DECLARE @vIdFlotte INT, @vProtocol VARCHAR(30), @vIdSystem INT, @vEcuHardware VARCHAR(30), 
			@vEcuType VARCHAR(30), @vEngineProject VARCHAR(30), @vDisplacement NUMERIC, 
			@vEmissionConcept VARCHAR(30), @vPlatform VARCHAR(30), @vPower VARCHAR(30), 
			@vGearbox VARCHAR(30), @vVehicle VARCHAR(30), @vManufacturer VARCHAR(30), 
			
	
    DECLARE @vAccion AS VARCHAR(4000)

    OPEN curIns;
    
	FETCH curIns INTO @vIdFlotte, @vProtocol, @vIdSystem, @vEcuHardware, 
			@vEcuType, @vEngineProject, @vDisplacement, 
			@vEmissionConcept, @vPlatform, @vPower, 
			@vGearbox, @vVehicle, @vManufacturer, 
			
    
  WHILE @@FETCH_STATUS=0
  BEGIN
	SET @vAccion='INSERT. '+'IdFlotte=' + CONVERT(VARCHAR,@vIdFlotte)+'; '+'Protocol='+@vProtocol+'; '+'IdSystem=' + CONVERT(VARCHAR,@vIdSystem)+'; '+'EcuHardware='+@vEcuHardware+'; '+'EcuType='+@vEcuType+'; '+'EngineProject='+@vEngineProject+'; '+'Displacement='+@vDisplacement+'; '+'EmissionConcept='+@vEmissionConcept+'; '+'Platform='+@vPlatform+'; '+'Power='+@vPower+'; '+'Gearbox='+@vGearbox+'; '+'Vehicle='+@vVehicle+'; '+'Manufacturer='+@vManufacturer
	
	INSERT obd.LOGMOVIMIENTOS (tabla, idReg, fecha, 
							   user_Id, accion)
    VALUES ('Flotte', @vIdReg, GETDATE(), 
			@vUser_Id, @vAccion)
  END
    
END
GO
